page.tsx 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. "use server";
  2. import { BannerRep, GroupType, NoticeRep, PromotionRep } from "@/api/home";
  3. import Box from "@/components/Box";
  4. import HomeActions from "./_home/HomeActions";
  5. import HomeCard from "./_home/HomeCard";
  6. import HomeGames from "./_home/HomeGames";
  7. import HomeMessage from "./_home/HomeMessage";
  8. import HomeNoticeBar from "./_home/HomeNoticeBar";
  9. import HomePrize from "./_home/HomePrize";
  10. import HomePromotion from "./_home/HomePromotion";
  11. import HomeSearch from "./_home/HomeSearch";
  12. import HomeSwiper from "./_home/HomeSwiper";
  13. import HomeTabs from "./_home/HomeTabs";
  14. const BASE_URL = process.env.NEXT_PUBLIC_BASE_URL;
  15. const TIME = 30;
  16. const getGames = async (): Promise<GroupType[]> => {
  17. try {
  18. const data = await fetch(`${BASE_URL}/v1/api/front/game_list`, {
  19. method: "POST",
  20. body: JSON.stringify({ template_key: "g_temp_9" }),
  21. next: { revalidate: TIME },
  22. }).then((res) => res.json());
  23. console.log(`🎯🎯🎯🎯🎯-> in page.tsx on 24`, data.data);
  24. return data.data;
  25. } catch (err) {
  26. return [];
  27. }
  28. };
  29. const getBanners = async (): Promise<BannerRep[]> => {
  30. try {
  31. const response = await fetch(`${BASE_URL}/v1/api/front/banner_list`, {
  32. method: "POST",
  33. body: JSON.stringify({}),
  34. headers: {
  35. language: "zh",
  36. },
  37. next: { revalidate: TIME },
  38. }).then((res) => res.json());
  39. return response.data;
  40. } catch (err) {
  41. return Promise.resolve([]);
  42. }
  43. };
  44. const getNotices = async (): Promise<NoticeRep[]> => {
  45. try {
  46. const response = await fetch(`${BASE_URL}/v1/api/front/marquee`, {
  47. method: "POST",
  48. body: JSON.stringify({}),
  49. headers: {
  50. language: "zh",
  51. },
  52. next: { revalidate: TIME },
  53. }).then((res) => res.json());
  54. return response.data;
  55. } catch (err) {
  56. return [];
  57. }
  58. };
  59. const getActivities = async (): Promise<BannerRep[]> => {
  60. try {
  61. const response = await fetch(`${BASE_URL}/v1/api/front/activity_home`, {
  62. method: "POST",
  63. body: JSON.stringify({}),
  64. headers: {
  65. language: "zh",
  66. },
  67. next: { revalidate: TIME },
  68. }).then((res) => res.json());
  69. return response.data;
  70. } catch (err) {
  71. return [];
  72. }
  73. };
  74. const getPromotions = async (): Promise<PromotionRep[]> => {
  75. try {
  76. const response = await fetch(`${BASE_URL}/v1/api/front/pop_list`, {
  77. method: "POST",
  78. body: JSON.stringify({}),
  79. headers: {
  80. language: "zh",
  81. },
  82. next: { revalidate: TIME },
  83. }).then((res) => res.json());
  84. return response.data;
  85. } catch (err) {
  86. return [];
  87. }
  88. };
  89. export default async function Page() {
  90. const [group = [], banners = [], notices = [], activities = [], promotions = []] =
  91. await Promise.all([
  92. getGames(),
  93. getBanners(),
  94. getNotices(),
  95. getActivities(),
  96. getPromotions(),
  97. ]);
  98. return (
  99. <div>
  100. <HomeMessage />
  101. <HomePromotion data={promotions} />
  102. <Box>
  103. <HomeSwiper banners={banners}></HomeSwiper>
  104. <HomeCard banners={activities}></HomeCard>
  105. <HomeNoticeBar notices={notices} />
  106. <HomeSearch />
  107. <HomePrize></HomePrize>
  108. <HomeTabs />
  109. </Box>
  110. {group.map((item) => {
  111. return <HomeGames groupGames={item.category} key={item.category_name} />;
  112. })}
  113. <Box>
  114. <HomeActions />
  115. </Box>
  116. </div>
  117. );
  118. }